package org.programmers.anonymous.fightrobots.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * This class implements the URLIdobject, which allows managing
 * the IP and Robot_ID peers. 
 * 
 * @author David Rodriguez, Francisco Villalba
 *
 */
public class URLId implements IURLId{

	/**
	 * Private attributes
	 */
	private String myURL, myRobotId;

	/**
	 * Simple Constructor
	 */
	public URLId(){
		this.myURL = null;
		this.myRobotId = null;
	}

	
	/**
	 * Composed constructor
	 * @param url - The url
	 * @param robotID - The robot Id
	 */
	public URLId(String url, String robotID){
		this.myURL = url;
		this.myRobotId = robotID;
	}
	

	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IURLId#getURL()
	 */
	public String getURL() {
		return this.myURL;
	}

	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IURLId#getRobotId()
	 */
	public String getRobotId() {
		return this.myRobotId;
	}

	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IURLId#setURL(java.lang.String)
	 */
	public void setURL(String newURL) {
		this.myURL = newURL;

	}
	
	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IURLId#setRobotId(java.lang.String)
	 */
	public void setRobotId(String newRobotId) {
		this.myRobotId = newRobotId;	
	}

	@Override
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return this.myURL + ":" + this.myRobotId;
	}

	@Override
	 public int hashCode() {
	        return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
	            // if deriving: appendSuper(super.hashCode()).
	            append(myURL).
	            append(myRobotId).
	            toHashCode();
	}

	
	@Override
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj){
		
		if (obj == null)
            return false;
        if (obj == this)
            return true;
        if (!(obj instanceof IURLId))
            return false;

		IURLId w = (IURLId) obj;
		

        return new EqualsBuilder().
                // if deriving: appendSuper(super.equals(obj)).
                append(myURL, w.getURL()).
                append(myRobotId, w.getRobotId()).
                isEquals();
		/*
		if(this.toString().equalsIgnoreCase(w.toString()))
		{
			return true;
		}
		else
		{
			return false;
		}*/


	}
	
	


}



